package cn.chl.controller;

import cn.chl.domain.Build;
import cn.chl.domain.Floor;
import cn.chl.dto.DeviceListByBuildIdDto;
import cn.chl.result.JSONResult;
import cn.chl.service.IBuildService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/build")
@RefreshScope // 动态刷新配置注解
public class BuildController {

    @Autowired
    private IBuildService buildService;

    /**
     * 批量添加楼层
     */
    @PostMapping("/addFloor")
    public JSONResult addFloor(@RequestBody List<Floor> list){
        buildService.addFloor(list);
        return new JSONResult(true,"添加成功");
    }

    /**
     * 根据楼宇id查询设备localhost:8080/api/build/getDeviceListByBuildId?id=
     */
    @GetMapping("/getDeviceListByBuildId/{id}")
    public JSONResult getDeviceListByBuildId(@PathVariable("id")Integer id){
        DeviceListByBuildIdDto dto = buildService.getDeviceListByBuildId(id);
        return new JSONResult(true,"查询成功",dto);
    }

    /**
     * 根据设备类型查询所有设备localhost:8080/api/build/getDeviceListByDeviceType?type=
     */
    @GetMapping("/getDeviceListByDeviceType/{type}")
    public JSONResult getDeviceListByDeviceType(@PathVariable("type")Integer type){
        List<DeviceListByBuildIdDto> list = buildService.getDeviceListByDeviceType(type);
        return new JSONResult(true,"请求成功",list);
    }

    /**
     * 查询单个楼栋
     */
    @GetMapping("/getOne/{id}")
    public JSONResult getOne(@PathVariable("id") Integer id){
        Build build = buildService.getOne(id);
        return new JSONResult(true,"查询成功",build);
    }
}
